animationtime = 750;
$(document).ready(function (){
	
    var dateTimePickerOptions = {
	firstDay: 1,
	showSecond: false,
	dateFormat: 'dd.mm.yy',
	timeFormat: 'HH:mm',
	stepHour: 1,
	stepMinute: 15,
	locale: 'de_DE'
    };
    dateFrom=Date.parseExact($('#date_from').val(),'dd.MM.yyyy HH:mm');
    dateTo=Date.parseExact($('#date_to').val(),'dd.MM.yyyy HH:mm');
    dateDifference=new TimeSpan(dateTo-dateFrom);
    $('#date_from').change(function(){
	$('#date_to').val(Date.parseExact($('#date_from').val(),'dd.MM.yyyy HH:mm').add({ days: dateDifference.days, hours: dateDifference.hours, minutes: dateDifference.minutes}).toString('dd.MM.yyyy HH:mm'));
    });
    $('#date_to').change(function(){
	dateFrom=Date.parseExact($('#date_from').val(),'dd.MM.yyyy HH:mm');
	dateTo=Date.parseExact($('#date_to').val(),'dd.MM.yyyy HH:mm');
	dateDifference=new TimeSpan(dateTo-dateFrom);
    });
    $('#date_from').datetimepicker(dateTimePickerOptions);
	
    $('#date_from').change(function(){
	if ($.trim($('#date_to').val()) == "" ||  $.trim($('#date_to').val()).indexOf('00:00') != -1){
	    $('#date_to').val($('#date_from').val());
	}
    });
	
	
    $('#date_to').datetimepicker(dateTimePickerOptions);
	
    $('#last_date').datepicker(dateTimePickerOptions);

    $('#frequence').change(function(){
	if ($(this).val() == 'WEEKLY'){
	    $('#last_date').fadeIn(animationtime);
	    $('#last_date-label label').fadeIn(animationtime);
	}else{
	    $('#last_date').fadeOut(animationtime);
	    $('#last_date-label label').fadeOut(animationtime);
	}
    });
    $('#event_type').change(function(){
	if ($(this).val() == "Eingewöhnungstermin" ||
	    $(this).val() == "Fester Termin" ||
	    $(this).val() == "Einzeltermin" ||
	    $(this).val() == "Abgesagter Termin" ||
	    $(this).val() == "Gesprächstermin"){
	    $('#child_id').fadeIn(animationtime);
	    $('#child_id-label label').fadeIn(animationtime);
	}else{    
	    $('#child_id').fadeOut(animationtime);
	    $('#child_id-label label').fadeOut(animationtime);
	}
    });
});